#!/bin/sh
#
# see: dh_installdeb(1)

set -e

# avoid cancelling of "stop" via socket or D-Bus activation
if [ -d /run/systemd/system ] && [ "$1" = remove ]; then
	systemctl mask --runtime nodered.service || true
	# stop ${service}.service manually since invoke-rc.d currently doesn't
	# deal with masked services (see Bug #717109)
	systemctl stop nodered.service || true

	systemctl mask --runtime node-red.service || true
	# stop ${service}.service manually since invoke-rc.d currently doesn't
	# deal with masked services (see Bug #717109)
	systemctl stop node-red.service || true
fi

# summary of how this script can be called:
#        * <prerm> `remove'
#        * <old-prerm> `upgrade' <new-version>
#        * <new-prerm> `failed-upgrade' <old-version>
#        * <conflictor's-prerm> `remove' `in-favour' <package> <new-version>
#        * <deconfigured's-prerm> `deconfigure' `in-favour'
#          <package-being-installed> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

remove_file () {
	if [ -f ${wfile} ] ; then
		rm -f ${wfile} || true
	fi
}

remove_dir () {
	if [ -d ${wdir} ] ; then
		rm -rf ${wdir} || true
	fi
}

remove_all () {
	wfile="/etc/avahi/services/node-red.service" ; remove_file
	wfile="/etc/avahi/services/nodered.service" ; remove_file
}

case "$1" in
    remove|upgrade|deconfigure)
	remove_all
    ;;

    failed-upgrade)
    ;;

    *)
        echo "prerm called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
